import { requestFunComponFiex } from '@/utils';
import { useMemo } from 'react';
import { useRequest } from 'umi';
import { ManageCommonAPI } from '@/pages/type';
import { getBaseUrl } from '@/services/urlconst';

const baseUrl = getBaseUrl();

/**
 * 管理页面处理数据
 * @param curRes  权限参数
 */
const SelectBankService = (callback = (res) => {}) => {
  /** 获取列表数据  */
  const { tableProps, data, loading, run, refresh } = useRequest(
    (opt: ManageCommonAPI.IGridRequestType) => {
      const requestBody: Record<string, any> = {
        current: 1,
        pageSize: 10,
        sort: 'createTime',
        order: 'desc',
        selectSign: false,
        ...opt,
      };

      const requestURL = `${baseUrl}/supplierInfoController/getBankByName`;
      return requestFunComponFiex('POST', requestURL, requestBody);
    },
    {
      manual: false, //页面初始请求为 true
      paginated: true,
      defaultPageSize: 10,
      onSuccess: callback,
    },
  );

  /* 获取页面数据 */
  const getBankRun = (otherRequest: ManageCommonAPI.IGridRequestType | any) => {
    const request: ManageCommonAPI.IGridRequestType | any = { ...otherRequest };
    run({ ...request });
  };

  /**
   * 页面列表
   */
  let returnTableProps = useMemo(() => {
    return {
      data,
      pagination: tableProps?.pagination,
    };
  }, [data, tableProps]);

  return {
    loading,
    getBankRun,
    reloadRefresh: refresh,
    ...returnTableProps,
  };
};

export { SelectBankService };
